--get the addon namespace
local addon, ns = ...

local LabelUI = ns.LabelUI
local point = LabelUI.point
local cfg = ns.cfg

local function Init()
   local barcfg = cfg.bars.extrabar
   if barcfg and not barcfg.disable then

  --holder frame
  local bar = CreateFrame("Frame","rABS_ExtraActionBar",UIParent,"SecureHandlerStateTemplate")
  bar:SetSize(barcfg.buttonsize,barcfg.buttonsize)
  bar:SetPoint(barcfg.pos.a1,point(barcfg.pos.af),barcfg.pos.a2,barcfg.pos.x,barcfg.pos.y)
  bar:SetHitRectInsets(-cfg.background.inset, -cfg.background.inset, -cfg.background.inset, -cfg.background.inset)
  bar:SetScale(barcfg.barscale)

  if barcfg.testmode then
    bar:SetBackdrop(cfg.backdrop)
    bar:SetBackdropColor(1,0.8,1,0.6)
  end
  
  bar:SetID(6)

  --the frame
  local f = ExtraActionBarFrame
  f:SetParent(bar)
  f:EnableMouse(false)
  f:ClearAllPoints()
  f:SetPoint("CENTER", 0, 0)
  f.ignoreFramePositionManager = true

  --the button
  local b = ExtraActionButton1
  b:SetSize(barcfg.buttonsize,barcfg.buttonsize)
  bar.button = b

  RegisterStateDriver(bar, "visibility", "[petbattle][overridebar][vehicleui] hide; show")
  
  --register the event, make sure the damn button shows up
  --[[bar:RegisterEvent("UPDATE_EXTRA_ACTIONBAR")
  bar:RegisterEvent("PLAYER_REGEN_ENABLED")
  bar:SetScript("OnEvent", function(self, event, ...)
    if (HasExtraActionBar()) then
      self:Show()
      self.button:Show()
    else
      self:Hide()
    end
  end)
--]]
end --disable
end
LabelUI:AddInit(Init, "ExtraBar")
